
Session 2: (Re) Introduction to R
I want to know you:
I want you to answer four questions:

There are 5 basic types of objects in the R language:


[1] 8
[1] 10 15 20 22 25 25 36 60
[1] 213
[1] 10
[1] 26.625
[1] 23.5
[1] 15.50979
[1] 240.5536
Min. 1st Qu. Median Mean 3rd Qu. Max.
10.00 18.75 23.50 26.62 27.75 60.00
#1.-Create a list containing strings, numbers, vectors and a logical values.
#2.-Create a dataframe of 5 variables
#Hint: Remember the length of the vectors
#3.- Create a vector with numerical values and strings with a length of 10
#4.- Assign the following vectors to a meaningful variable name:
#Hint: Remember the assignment operator.
c(2, 4, 6, 8, 10, 12, 14, 16, 20)
0
3.141593
c(1, 10, 100, 1000, 10000, 100000)
#5.- Create vectors that correspond to the following variables names:
yourage
days_of_the_week
firstFivePrimeNumbers#1.-Create a list containing strings, numbers, vectors and a logical values.
list <- list(c("Coding", "Club"), c(1,2,3), 7)
#2.-Create a dataframe of 5 variables
#Hint: Remember the length of the vectors
df_my_family <- data.frame(number = c(1,2,3),
age = c(17,18,19),
name = c("Alex", "Eduardo", "Jorge"),
favorite_color = c("blue", "orange", "black"),
favorite_number = c(20, "5", 50))
#3.- Create a vector with numerical values and strings with a length of 10
vector <- c(1,2,3,"number",99, 100, "yes", "hi", 9, 10)
length(vector)
#4.- Assign the following vectors to a meaningful variable name:
#Hint: Remember the assignment operator.
vector <- c(2, 4, 6, 8, 10, 12, 14, 16, 20)
value <- 0
value_2 <- 3.141593
num_vector <- c(1, 10, 100, 1000, 10000, 100000)
#5.- Create vectors that correspond to the following variables names:
yourage <- c(25)
days_of_the_week <- c("Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday",
"Sunday")
firstFivePrimeNumbers <- c(2,3,5,7,11)

Website and cloud-based service to store and manage code
Git IDE: used in the programming world. It is used for tracking changes in the source code during software development.
It makes it easier for individuals and teams to use Git for version control and collaboration.







CONGRATULATIONS: YOU CREATED YOUR FIRST REPO
R packages are a collection of R functions, complied code and sample data.
Why: There are millions of functions. If they were all preloaded, there wouldn’t be enough RAM to work with. There are packages of such varied disciplines that we likely use relatively few.
They are stored under a directory called “library” in the R environment.
By default, R installs a set of packages during installation. More packages are added later, when they are needed for some specific purpose.
When we start the R console, only the default packages are available by default.
Other packages which are already installed have to be loaded explicitly to be used by the R program that is going to use them.
We can also generate our functions and even create an R package!

Package set for: Import, Clean, Transform, Process, Analyze and Visualize

readr
Package set for: load plain text files (txt, csv, tsv)

readxl
Package set for: load excel files (xls, xlsx)

haven
Package set for: Display proprietary formats (dta, sav). Like STATA and other formats.

tidyr
Package set for: transform dataframe structures

lubridate
Package set for: wrangling dates. Tools that make working with dates and times easier.

stringr
Package set for: wrangling string or characters.

dplyr
Package set for: wrangling dataframes. facilitates several functions for the data frames in R. dplyr package is for data wrangling and data analysis purposes.

ggplot
Package set for: plots and maps. One of the most popular visualization package in R.

The easy way



The easy way


Example
We will work with Airbnb accommodation data in Berlin as of September 15, 2022. They are open data available at Airbnb: get the data.
They are open data licensed under the Creative Commons CC0 1.0 Universal “Public Domain Dedication.
Those who stay can choose between entire houses/apartments, only private rooms, or shared rooms (room_type).
After the stay, they must leave an evaluation (review).
Accommodations vary in price, a minimum number of days of stay, days available, etc.

